package com.hmall.order.mq;



import com.hmall.order.constants.ItemMqConstants;
import com.hmall.order.pojo.Order;
import com.hmall.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @Author dml
 * Date on 2022/7/10 0010
 */

@Component
@Slf4j
public class ItemListener {

    @Autowired
    private IOrderService orderService;

//    @RabbitListener(queues= ItemMqConstants.INSERT_QUEUE_NAME)
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "delay.queue",durable = "true"),
            exchange = @Exchange(name = "delay.direct",delayed = "true"),
            key = "delay"
    ))
    public void listenHotelInsertOrUpdate(Long id) throws InterruptedException {

//        TimeUnit.SECONDS.sleep(10);
        orderService.updateByIds(id);
    }



//    @RabbitListener(queues= ItemMqConstants.DELETE_QUEUE_NAME)
//    public void listenHotelDelete(Long id){
//        orderService.deleteById(id);
//    }
}
